package cn.edu.scujcc.customofsichuan.DataBase;

import android.content.Context;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;

import cn.edu.scujcc.customofsichuan.Dao.UserDao;
import cn.edu.scujcc.customofsichuan.Entity.User;

@Database(entities = {User.class},version = 1,exportSchema = false)
public abstract class UserDatabase extends RoomDatabase {
    //定义常量数据库名，用于databaseBuilder的第三个参数
    public static final String DATABASE_NAME="user.db";
    //定义一个全局实例对象
    private static UserDatabase instance;

    //单例模式
    public static synchronized UserDatabase getInstance(Context context){
        if (instance==null){
            instance= Room.databaseBuilder(context.getApplicationContext(),
                    UserDatabase.class,
                    DATABASE_NAME
                    ).build();
        }
        return instance;
    }

    //获取一个UserDao对象,是通过Room自动创建的
    public abstract UserDao getUserDao();

}
